package com.mask.aop.proxy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * ClassName UserServiceProxy
 * Create by hx
 * Date 2021/9/23 10:57 上午
 * 切面类
 */

@Aspect
@Component
public class UserServiceProxy {
    /**
     * 前置通知，在目标方法之前增强执行
     */
    public void beforeMethodProxy(){
        System.out.println("执行前置通知");
    }

    /**
     * 定义后置通知
     */
    public void afterMethodProxy(){
        System.out.println("执行后置通知");
    }

    /**
     * 定义环绕通知
     * @param joinPoint
     * @throws Throwable
     */
    public void aroundMethodProxy(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("我是环绕通知，在之前执行通知");
        joinPoint.proceed();
        System.out.println("我是环绕通知，在之后执行通知");
    }

    /**
     * 异常通知
     */
    public void exceptionMethodProxy1(){
        System.out.println("我是异常通知，在出现异常的时候执行");
    }

    /**
     * 异常通知
     */
    public void exceptionMethodProxy2(){
        System.out.println("我是异常通知，在出现异常的时候执行");
    }

    @After("execution(* save*(..))")
    public void queryMethodProxy(){
        System.out.println("save方法执行之后操作saved");
    }

    @Around("execution(* com.mask.aop.service.impl.UserServiceImpl.del*(..))")
//    @Around("execution(* delete*(..))")
    public void deleteAroundProxy(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("delete环绕通知前 deleting before");
        joinPoint.proceed();
        System.out.println("delete环绕通知后 delete over");


    }



}
